/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import DAO.Iter.GiaoVienDAO;
import TableModel.Giaovien;
import TableModel.Hocphan;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


/**
 *
 * @author vt
 */
public class GiaoVienDAOImpl extends HibernateDaoSupport implements GiaoVienDAO{

    @Override
    public List<Giaovien> findAllGiaoVien() {
      return  getHibernateTemplate().find("from Giaovien");
    }
    @Override
    public void add(Giaovien a){
        
        getHibernateTemplate().save(a);
    }
    @Override
    public void update(Giaovien a) {
      
        getHibernateTemplate().saveOrUpdate(a);
    }

    @Override
    public void delete(Giaovien a) {
        getHibernateTemplate().delete(a);
    }

    @Override
    public Giaovien findGiaoVien(String id) {
    List list1 = this.getHibernateTemplate().find("from Giaovien giaovien where giaovien.magv = ?", id);
		if(list1.isEmpty()){
			return null;
		}
		return (Giaovien) list1.get(0);
    }

    @Override
    public Giaovien findAdmin(String userName, String paawrod) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Giaovien findGiaoVien(String name, String pass) {
       List list = this.getHibernateTemplate().find("from Giaovien giaovien where giaovien.name = ? and giaovien.password = ?", name,pass);
		if(list.isEmpty()){
			return null;
		}
		return (Giaovien) list.get(0);

    }
   /**
     * lay tat ca danh sach hoc phan thuoc ve sinh vien
     * @param id id giao vien
     * @return  danh sash hoc phan cua giao vien sap xep theo ten
     */
    @Override
    public List<Hocphan> listHocPhan(String id) {
      return this.getHibernateTemplate().find("from Hocphan hocphan where hocphan.magv = ?", id);
    }
    
}
